module Cool
  class TabularFormBuilder < ActionView::Helpers::FormBuilder
    def self.create_cool_field(method_name)
      define_method(method_name) do |label,*args|
        _label = args.last[:label] if args.last.is_a?(Hash)
        _label = label.to_s.humanize if _label.blank?
        
        if method_name == "submit_tag"
          @template.content_tag("td", "<input type='submit' value='#{label}' name='commit'/>")
        elsif method_name == "date_select"
          @template.content_tag("td",
             calendar_date_select("#{label}", :time => false))
        elsif method_name == "datetime_select"
          @template.content_tag("td",
             calendar_date_select("#{label}", :time => true))
        else
       @template.content_tag("tr",
         @template.content_tag("td",
           @template.content_tag("label", 
             _label,
             :for => "#{@object_name}_#{label}")) + 
           @template.content_tag("td",
           super))
           end
      end
    end
    
    total_field_helpers = %w{ select calendar_date_select file_field check_box 
        password_field  date_select country_select collection_select 
        time_select datetime_select text_field   
        radio_button text_area time_zone_select submit_tag editable_drop_down }

    total_field_helpers.each do |name|
      alias_method "pure_#{name}",name if name != "submit_tag"
    end
    
    total_field_helpers.each do |name|
      create_cool_field(name)
    end
    
  end
  
end 